<template>
  <div class="tree bg-white">
    <BasicTree title="设备列表" treeWrapperClassName="h-[calc(100%-35px)] overflow-auto" :clickRowToExpand="false"
      :treeData="treeData" :fieldNames="{ key: 'id', title: 'deptName' }" @select="handleSelect" />
  </div>
</template>
<script lang="ts"
  setup>
  import { onMounted, ref } from 'vue';

  import { BasicTree, TreeItem } from '@/components/Tree';
  import { getClassifyTree } from '@/api/collection/classify';

  defineOptions({ name: 'DeptTree' });

  const emit = defineEmits(['select']);

  const treeData = ref<TreeItem[]>([]);

  async function fetch() {
    treeData.value = (await getClassifyTree({})) as unknown as TreeItem[];
  }

  function handleSelect(keys) {
    emit('select', keys[0]);
  }

  onMounted(() => {
    fetch();
  });
</script>
<style scoped>
.tree {
  flex-shrink: 0;
  margin-right: 8px;
}
</style>
